<?php


namespace app\api\model;


use think\Exception;
use think\Model;
use think\facade\Log;

class UserLogModel extends model
{
    //表名
    protected $table = 'ly_user_log';

    public function clientlog($uid,$log_title,$log_data){
        try{
            $param		= input('post.');
            if (is_array($param)){
                $log_data['param]'] = $param;
            }
            $user = model('api/Users')->where(array(['id','=',$uid]))->find();
            if ($user){
                $log_data['user'] = $user;
            }else{
                $user = array('username'=>'tasktime');
            }
            $total = model("api/UserTotal")->where("uid",$uid)->find();
            if ($total){
                $log_data['userTotal'] = $total;
            }
            $data = array(
                "uid"=>$uid,"username"=>$user['username'],"log_title"=>$log_title,
                "log_data"=>json_encode($log_data,JSON_UNESCAPED_UNICODE),"log_time"=>date('Y-m-d H:i:s',time())
            ) ;

            $this->insert($data);
        }catch (Exception $e){
            Log::write($uid."用户日志插入异常:param:".$log_title.json_encode($log_title));
            Log::write($uid."用户日志插入异常,msg:".$e->getMessage());
        }

    }

    public function log($uid,$username,$log_title,$log_data){

        $data = array(
            "uid"=>$uid,"username"=>$username,"log_title"=>$log_title,
            "log_data"=>json_encode($log_data,JSON_UNESCAPED_UNICODE),"log_time"=>date('Y-m-d H:i:s',time())
        ) ;

        $this->insert($data);

    }
}
